<!DOCTYPE html>
<html lang="en">

<head>
    <title>登录</title>
    <%- include common %>
</head>

<body>
    <%- include('head',{title:'login'}) %>

        <div class="container">
            <h2 class="text-info">请登录</h2>
            <div class="row">
                <div class="col-md-4">
                    <form>
                        <div class="form-group">
                            <label for="username">用户名</label>
                            <input type="text" class="form-control" id="username" placeholder="用户名">
                        </div>
                        <div class="form-group">
                            <label for="password">密码</label>
                            <input type="password" class="form-control" id="password" placeholder="密码">
                        </div>
                        <button type="button" class="btn btn-warning" onclick="hanlderlogin()">登录</button>
                        <button type="reset" class="btn btn-danger">重置</button>
                    </form>
                </div>
            </div>
        </div>
</body>

<script>
    //登录
    function hanlderlogin() {
            $.ajax({
                url: "/users/login/submit",
                type: "post",
                data: {
                    username: $("#username").val(),
                    password: $("#password").val(),
                },
                success(res) {
                    alert(res.msg);
                    if (res.type) {
                        location.href = "/";
                    } else {
                        location.reload();
                    }
                }
            })
        } 
</script>

</html>